include_directories(${CMAKEDEMO_SOURCE_DIR}/src)
link_directories(${CMAKEDEMO_BINARY_DIR}/src)

#the one C file
add_executable(SquareRt SquareRt.c)
target_link_libraries(SquareRt m) #link the math library

# Compile programs that have the same requirement
set(PROGRAMS oglfirst pointers)
set(CORELIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} m)

foreach(program ${PROGRAMS})
  add_executable(${program} ${program}.cpp)
  target_link_libraries(${program} ${CORELIBS})
endforeach(program)

add_library(geometry geometry.cpp)

# build the last program
add_executable(test_geometry test_geometry.cpp)

# linking against a custom library
target_link_libraries(test_geometry ${CORELIBS} geometry)

# Install to desired directories
INSTALL(TARGETS SquareRt oglfirst pointers test_geometry geometry
	RUNTIME DESTINATION ${CMAKEDEMO_BINARY_DIR}/bin
	ARCHIVE DESTINATION ${CMAKEDEMO_BINARY_DIR}/lib)

